package com.peng.test.jdk;

import java.text.ParseException;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Random;
import java.util.concurrent.TimeUnit;

/**
 * DateTimeUtils
 *
 * @author: lupeng6
 * @create: 2023/3/26 21:15
 */
public class DateTimeUtils {

    public static long localDateTime2ts(LocalDateTime localDateTime) {
        return localDateTime.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
    }

    public static LocalDateTime ts2LocalDateTime(long timestamp) {
        return LocalDateTime.ofInstant(Instant.ofEpochMilli(timestamp), ZoneId.systemDefault());
    }


    public static void main(String[] args) throws ParseException {
        // LocalDate localDate = LocalDate.now().plusDays(1);
        // LocalTime localTime = LocalTime.of(10, 0);
        // LocalDateTime dateTime = LocalDateTime.of(localDate, localTime);
        // System.out.println(dateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
        // long ms = dateTime.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
        // System.out.println(ms);
        // System.out.println((ms - System.currentTimeMillis()) / 1000);

        // System.out.println(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date(System.currentTimeMillis() + (80674 * 1000))));


        // SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        // Date date = simpleDateFormat.parse("2023-11-21 20:13:15");
        // System.out.println((System.currentTimeMillis() - date.getTime()) / 1000);

        // List<Integer> list = new ArrayList<>();
        // for (int i = 0; i < 101; i++) {
        //     list.add(i);
        // }
        // int shardingTotal = 3;
        // int partitionSize = list.size() % shardingTotal == 0 ? (list.size() / shardingTotal) : (list.size() / shardingTotal) + 1;
        // List<List<Integer>> partition = Lists.partition(list, partitionSize);
        // for (List<Integer> integers : partition) {
        //     System.out.println(Joiner.on(",").join(integers));
        // }

        for (int i = 0; i < 100; i++) {
            System.out.println(new Random().nextInt((int) TimeUnit.MINUTES.toMillis(30)));
        }
    }
}
